import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
Vue.use(ElementUI)
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

// 封装全局的指令 - 按钮控制权限
// 举例：员工管理模块 -> 添加员工按钮（不是对所有人开放）
Vue.directive('permission', {
  inserted(el, binding) {
    // 指令所绑定的元素被插入到页面中触发
  // el 指令所绑定的元素标签
    console.log('abc', el, binding)
    console.log(store.state.user.userInfo?.roles?.points)
    // 按钮权限数组
    const points = store.state.user.userInfo?.roles?.points || []
    // 判断指令的值是否存在于权限数组当中
    if (!points.includes(binding.value)) {
      // el.disabled = true  // 禁用
      el.remove() // 隐藏/移除
    }
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
console.log('环境变量', process.env.NUE_APP_BASE_API)
